/**
 * @ClassName LC258
 * @Author ykx
 * @Date 2024/3/10 15:48
 * @Version 1.0
 */
public class LC258 {

    public static void main(String[] args) {
        LC258 lc258 = new LC258();
        System.out.println(lc258.addDigits(38));
    }

    public int addDigits(int num) {
        int sum = 0;
        for (int i = num; i > 0; i = i / 10) {
            sum += i % 10;
        }
        if (sum >= 10) {
            return addDigits(sum);
        }
        return sum;
    }
}
